/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package com.broker.consumer.controller;

import java.util.List;
import java.util.Map;

import me.send.broker.entity.UserEvaluate;
import me.send.broker.entity.base.ReturnJsonBean;
import me.send.broker.enums.AuthodType;
import me.send.broker.pojo.BrokerEvaluateBean;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.broker.consumer.controller.base.BaseController;

/**
 * @author maxmin
 *
 * @date 2015年8月25日 下午5:01:43
 */
@Controller
@RequestMapping(value="/evaluate")
public class EvaluateController extends BaseController {
	
	/**
	 * 添加对用户的评价
	 * @param evaluate
	 * @return
	 * @author maxmin
	 * @date 2015年8月25日下午5:16:33
	 */
	@RequestMapping()
	@ResponseBody
	public ReturnJsonBean evaluate(UserEvaluate evaluate,String devicenumber){
		ReturnJsonBean rb = new ReturnJsonBean();
		int result = userEvaluateService.addEvaluate(evaluate);
		if (result>0) {
			rb.setCode(ReturnJsonBean.SUCCESS);
			rb.setMessage(ReturnJsonBean.SUCCESS_STR);
		}
		return rb;
	}
	
	@RequestMapping("/toevaluate")
	@ResponseBody
	public ReturnJsonBean toEvaluate(Integer orderid,String devicenumber){
		ReturnJsonBean rb = new ReturnJsonBean();
		try {
			Map<String, Object> user = userService.getUserByOrderId(orderid);
			rb.setCode(ReturnJsonBean.SUCCESS);
			rb.setMessage(ReturnJsonBean.SUCCESS_STR);
			rb.setDatas(user);
		} catch (Exception e) {
			saveException(AuthodType.tangjianglong.getName(), "EvaluateController", "toEvaluate", e);
			e.printStackTrace();
		}
		return rb;
	}
	
	/**
	 * 我对用户的评价列表
	 * @param brokerid
	 * @param type 1:我对用户的评价 2：用户对我的评价
	 * @param devicenumber
	 * @return
	 * @author maxmin
	 * @date 2015年9月16日下午5:26:31
	 */
	@RequestMapping(value="myevaluates")
	@ResponseBody
	public ReturnJsonBean myEvaluates(int brokerid,Long startid,int size,int type,String devicenumber){
		ReturnJsonBean rb = new ReturnJsonBean();
		try {
			if (type==1) {
				rb.setCode(ReturnJsonBean.SUCCESS);
				rb.setMessage(ReturnJsonBean.SUCCESS_STR);
				List<BrokerEvaluateBean> list = userEvaluateService.getMyEvaluates(brokerid, startid, size);
				rb.setDatas(list);
			}else if (type==2) {
				rb.setCode(ReturnJsonBean.SUCCESS);
				rb.setMessage(ReturnJsonBean.SUCCESS_STR);
				List<BrokerEvaluateBean> list = brokerEvaluateService.evaluateMe(brokerid, startid, size);
				rb.setDatas(list);
			}
		} catch (Exception e) {
			saveException(AuthodType.tangjianglong.getName(), "EvaluateController", "myEvaluates()", e);
			e.printStackTrace();
		}
		return rb;
	}
}
